package com.ruoyi.biz.report.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.biz.report.domain.BizReportConfig;
import com.ruoyi.biz.report.service.IBizReportConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报月Controller
 *
 * @author Fei.Cong
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/report/config" )
public class BizReportConfigController extends BaseController {

    @Autowired
    private IBizReportConfigService bizReportConfigService;

    /**
     * 查询报月列表
     */
    @PreAuthorize("@ss.hasPermi('report:config:list')" )
    @GetMapping("/list" )
    public AjaxResult list(BizReportConfig bizReportConfig) {
        LambdaQueryWrapper<BizReportConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        return success(bizReportConfigService.list(lambdaQueryWrapper));
    }

    /**
     * 分页查询报月列表
     */
    @PreAuthorize("@ss.hasPermi('report:config:list')" )
    @GetMapping("/page" )
    public TableDataInfo page(BizReportConfig bizReportConfig) {
        return getDataTable(bizReportConfigService.pageList(bizReportConfig, startPage()));
    }

    /**
     * 导出报月列表
     */
    @PreAuthorize("@ss.hasPermi('report:config:export')" )
    @Log(title = "报月" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, BizReportConfig bizReportConfig) {
        List<BizReportConfig> list = bizReportConfigService.queryList(bizReportConfig);
        ExcelUtil<BizReportConfig> util = new ExcelUtil<BizReportConfig>(BizReportConfig.class);
        util.exportExcel(response, list, "报月数据" );
    }

    /**
     * 获取报月详细信息
     */
    @PreAuthorize("@ss.hasPermi('report:config:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(bizReportConfigService.getById(id));
    }

    /**
     * 新增报月
     */
    @PreAuthorize("@ss.hasPermi('report:config:add')" )
    @Log(title = "报月" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizReportConfig bizReportConfig) {
        return toAjax(bizReportConfigService.save(bizReportConfig));
    }

    /**
     * 修改报月
     */
    @PreAuthorize("@ss.hasPermi('report:config:edit')" )
    @Log(title = "报月" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizReportConfig bizReportConfig) {
        return toAjax(bizReportConfigService.updateById(bizReportConfig));
    }

    /**
     * 删除报月
     */
    @PreAuthorize("@ss.hasPermi('report:config:remove')" )
    @Log(title = "报月" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(bizReportConfigService.removeBatchByIds(ids));
    }
}
